package flatlandRPG;
import org.lwjgl.util.Color;
import org.lwjgl.opengl.GL11;
import org.lwjgl.util.ReadableColor;

// -------------------------------------------------------------------------
/**
 * An abstract opengl object that can be subclassed to easily create new object
 * types.
 *
 * @author Evan Tatarka (evant)
 * @version 2011.04.03
 */
public abstract class GLObject extends Entity implements IDrawable
{
    /**
     * Defines the thickness of all 2D GL objects.
     */
    public static final float THICKNESS = 0.2f;

    private ReadableColor color; // The color of the object.

    /**
     * Create a new GLObject colored black, at the origin and with no rotation.
     */
    public GLObject()
    {
        color = new Color(255, 255, 255);
    }

    // ----------------------------------------------------------
    /**
     * Returns the color of the object.
     *
     * @return the color
     */
    public ReadableColor getColor()
    {
        return color;
    }


    // ----------------------------------------------------------
    /**
     * Sets the color of the object.
     *
     * @param color
     *            the color
     */
    public void setColor(ReadableColor color)
    {
        this.color = color;
    }


    // ----------------------------------------------------------
    /**
     * Draws the object, taking into account the position, rotation, and color.
     */
    public void draw()
    {
        GL11.glPushMatrix();
        GL11.glTranslatef(getX(), getY(), 0);
        GL11.glColor3ub(
            color.getRedByte(),
            color.getGreenByte(),
            color.getBlueByte());
        drawObject();
        GL11.glPopMatrix();
    }

    // ----------------------------------------------------------
    /**
     * Subclass this to define how to draw the object.
     */
    protected abstract void drawObject();
}
